<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>用户管理</title>
<%@include file="/common/head.jsp" %>
<link href="<%=request.getContextPath()%>/static/plugin/zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet">
<script src="<%=request.getContextPath()%>/static/plugin/zTree/js/jquery.ztree.all-3.5.min.js"></script>
<style>
    #content {
        position: absolute;
        top: 0;
        left: 240px;
        right: 10px;
        bottom: 0;
        box-sizing: border-box;
    }
    ul.ztree {
       width: 230px;
    }
</style>
</head>
<body class="iframe-page">
  <div class="tree-wrap">
    <div class="tree-title">用户身份列表</div>
    <div class="tree-content">
	    <ul id="orgTree" class="ztree"></ul>
	</div>
  </div>
    
    <div id="content">
        <iframe id="userFrame" frameborder="0" style="width: 100%;height: 100%" src="<%=request.getContextPath()%>/sys/user/initUser"></iframe>
    </div>
<script>
	var userFrame = document.getElementById("userFrame"),
	    ztree;
    $(function () {
		//初始化左侧组织机构树
		initOrgTree('orgTree', USER_CONST_URL.GET_TREE, 'code', 'pCode');
    });
    
    //初始化组织机构树
    function initOrgTree(treeId, url, idKey, pIdKey) {
    	var setting = {
                data: {
                    simpleData: {
                        enable: true,
                        idKey: idKey,
                        pIdKey: pIdKey
                    }
                },
                edit: {
                    enable: false,
                    drag: {
                        isMove: false
                    }
                },
                callback: {
                    onClick: selectUserByOrgCode,
                    onRightClick: forbidRightMenu
                }
            };
            
            $.sajax({
                url: url,
                onLoadSuccess: function(data) {
                    ztree = $.fn.zTree.init($('#' + treeId),setting,data.data);
                    expandNode();
                }
            });
    }
    
    // 展开树节点
    function expandNode() {
       var nodeCode = '${param.expandId}',
           node;
       if (nodeCode) {
           // 获取需要自动展开的节点
           node = ztree.getNodeByParam('code', nodeCode, null);
       } else {
           // nodeId为空,展开根节点
           node = ztree.getNodeByParam('pCode', null, null);
       }
       // 如果该节点不包含子节点,则展开其父节点
       if (node && !node.isParent) {
          node = node.getParentNode(); 
       }
       ztree.expandNode(node, true, false, true);
    }
    
    //点击组织机构树查询用户
    function selectUserByOrgCode(event, treeId, treeNode) {
        url = USER_CONST_URL.INIT_USER + "?org=" + treeNode.code;
        userFrame.src = url; 
        //选中节点
        ztree.selectNode(treeNode);
    }
   
   //阻止默认的右键菜单
   function forbidRightMenu(event, treeId, treeNode) {
	   document.oncontextmenu = function (){
	       return false;
	   };
   }
   
    //请求url
    var USER_CONST_URL = {
       	GET_TREE: basePath + "/sys/inner/getOrgTree",
       	INIT_USER: basePath + '/sys/user/initUser'
    };
    
</script>
</body>
</html>